package Control.Service.impl;
import Entity.Achievements;
import Entity.ModulesGrades;
import Entity.RolesUndertaken;
import Entity.Student;
import Control.Service.StudentService;
import Control.JSONController;
import java.util.Iterator;
import java.util.List;

/**
 * @author Group 77
 * @version 4.0
 */
public class StudentServiceImpl implements StudentService {
    private final JSONController json = new JSONController("student.json");
    private final JSONController json1 = new JSONController("modules.json");
    private final JSONController json2 = new JSONController("achievements.json");
    private final JSONController json3 = new JSONController("role.json");


    /**
     * check the id and passwords for students
     */
    @Override
    public Student student_Login_id(String id, String password) {
        List<Student> students = this.json.readArray(Student.class);
        Iterator var3 = students.iterator();

        Student c;

        do {
            if (!var3.hasNext()) {
                return null;
            }

            c = (Student) var3.next();
        } while (!c.getStudentid().equals(id));

        if (c.getPassword().equals(password)) {

            return c;
        } else
            return null;
    }
    /**
     * check the module number and student id
     */
    @Override
    public int moudule_check(int StudentId,String ModuleNumber) {
        List<ModulesGrades> M = this.json1.readArray(ModulesGrades.class);
        Iterator var4 = M.iterator();

        ModulesGrades c ;
        int j = 0;


        while (var4.hasNext()){
            c = (ModulesGrades) var4.next();
            if(c.getStudentsNumber() == StudentId && c.getModuleNumber().equals(ModuleNumber)){
                break;
            }
            j++;

        }
        return j;
    }
    /**
     * check the Role name and student id
     */
    @Override
    public int Role_check(int StudentId,String Role_name){
        List<RolesUndertaken> M = this.json3.readArray(RolesUndertaken.class);
        Iterator var5 = M.iterator();

        RolesUndertaken c ;
        int j = 0;


        while (var5.hasNext()){
            c = (RolesUndertaken) var5.next();
            if(c.getStudentsNumber() == StudentId && c.getRoleName().equals(Role_name)){
                break;
            }
            j++;

        }
        return j;
    }
    /**
     * check the Achievements name and student id
     */
    @Override
    public int Ach_check(int StudentId,String Ach_name){
        List<Achievements> M = this.json2.readArray(Achievements.class);
        Iterator var6 = M.iterator();

        Achievements c ;
        int j = 0;


        while (var6.hasNext()){
            c = (Achievements) var6.next();
            if(c.getStudentNum() == StudentId && c.getAchievement().equals(Ach_name)){
                break;
            }
            j++;

        }
        return j;
    }
}